<hr/>
<div class="row-fluid">
    <div class="span12">
        <button class="btn btn-success" id="btn_save">保存</button>
        <div class="widget-box">
            <div class="widget-title"> <span class="icon"> <i class="icon-pencil"></i> </span>
                <h5>密码信息</h5>
            </div>
            <div class="widget-content nopadding">
                <form class="form-horizontal" method="post" action="${request.contextPath}/account/changePassword" name="password_form" id="password_form">
                    <div class="control-group">
                        <label class="control-label">旧密码：</label>
                        <div class="controls">
                            <input type="password" name="old_password" id="old_password">
                        </div>
                    </div>
                    <div class="control-group">
                        <label class="control-label">新密码：</label>
                        <div class="controls">
                            <input type="password" name="new_password" id="new_password">
                        </div>
                    </div>
                    <div class="control-group">
                        <label class="control-label">确认密码：</label>
                        <div class="controls">
                            <input type="password" name="confirm_password" id="confirm_password">
                        </div>
                    </div>
                    <!--<div class="form-actions">-->
                        <!--<input type="submit" value="Validate" class="btn btn-success">-->
                        <!--<input type="reset" value="reset" class="btn btn-danger" >-->
                    <!--</div>-->
                </form>
            </div>
        </div>
    </div>
</div>
<script src="${request.contextPath}/js/jquery-1.12.2.min.js"></script>
<script src="${request.contextPath}/js/jquery.validate.js"></script>
<script src="${request.contextPath}/js/sweetalert.min.js"></script>
<script type="text/javascript">
    $(function(){

        $("#btn_save").click(function(){
            $("#password_form").submit();
        });

        $("#password_form").validate({
            submitHandler: function(form){
                $.ajax({
                    url: $(form).attr("action"),
                    type: "post",
                    data: $(form).serialize(),
                    success: function(result){
                        swal({
                            title: "信息提示",
                            text: result.status == "success" ? "恭喜，操作已完成！" : "很遗憾，操作失败了！",
                            type: result.status,
                            animation: "slide-from-top"
                        });
                    }
                });
            },
            rules:{
                old_password:{
                    required: true,
                    minlength:6,
                    maxlength:20,
                },
                new_password:{
                    required: true,
                    minlength:6,
                    maxlength:20
                },
                confirm_password:{
                    required:true,
                    minlength:6,
                    maxlength:20,
                    equalTo:"#new_password"
                }
            },
            errorClass: "help-inline",
            errorElement: "span",
            highlight:function(element, errorClass, validClass) {
                $(element).parents('.control-group').addClass('error');
            },
            unhighlight: function(element, errorClass, validClass) {
                $(element).parents('.control-group').removeClass('error');
                $(element).parents('.control-group').addClass('success');
            }
        });
    });
</script>